Add GtkEntry icon signals emitter
authorEmmanuele Bassi <ebassi@gnome.org>
Thu, 15 Oct 2020 20:13:19 +0000 (21:13 +0100)
committerEmmanuele Bassi <ebassi@gnome.org>
Thu, 15 Oct 2020 23:34:01 +0000 (00:34 +0100)
We need a (private) way to programmatically trigger the activation of
the entry's icons, so that we can call it from the accessibility layer.

gtk/gtkentry.c
gtk/gtkentryprivate.h

index 532d3896fe740bf43455f17f2cc9ea7a29b57bdd..3717dcea2a14d71f8d39e52d8b2030be1d129409 100644 (file)
@@ -3723,3 +3723,36 @@ gtk_entry_get_extra_menu (GtkEntry *entry)
 
   return gtk_text_get_extra_menu (GTK_TEXT (priv->text));
 }
+
+/*< private >
+ * gtk_entry_activate_icon:
+ * @entry: a #GtkEntry
+ * @pos: the icon position
+ *
+ * Emits the #GtkEntry::icon-press and #GtkEntry::icon-release signals on
+ * the @entry icon at the given @pos, if the icon is set and activatable.
+ *
+ * Returns: %TRUE if the signal was emitted
+ */
+gboolean
+gtk_entry_activate_icon (GtkEntry             *entry,
+                         GtkEntryIconPosition  pos)
+{
+  GtkEntryPrivate *priv = gtk_entry_get_instance_private (entry);
+  EntryIconInfo *icon_info;
+
+  g_return_val_if_fail (GTK_IS_ENTRY (entry), FALSE);
+
+  icon_info = priv->icons[pos];
+
+  if (icon_info != NULL &&
+      gtk_image_get_storage_type (GTK_IMAGE (icon_info->widget)) != GTK_IMAGE_EMPTY &&
+      !icon_info->nonactivatable)
+    {
+      g_signal_emit (entry, signals[ICON_PRESS], 0, pos);
+      g_signal_emit (entry, signals[ICON_RELEASE], 0, pos);
+      return TRUE;
+    }
+
+  return FALSE;
+}
index eb98ac938dd5c976576ff1f5ecaffd824b754eba..05e4c6addba99f05cbfec3b6b467a33106adbc10 100644 (file)
@@ -106,6 +106,9 @@ GtkIMContext * _gtk_entry_get_im_context    (GtkEntry  *entry);
 GtkEventController * gtk_entry_get_key_controller (GtkEntry *entry);
 GtkText *gtk_entry_get_text_widget (GtkEntry *entry);
 
+gboolean gtk_entry_activate_icon (GtkEntry             *entry,
+                                  GtkEntryIconPosition  pos);
+
 G_END_DECLS
 
 #endif /* __GTK_ENTRY_PRIVATE_H__ */